﻿namespace Cloudio.Web.UI.Dock
{
    using System;
    using ASP = System.Web.UI.WebControls;
    using System.Web.UI;
    using Gaia.WebWidgets.Extensions;
    using Gaia.WebWidgets;

    public class DockingContainer : Panel
    {
        private readonly Panel _pnlTopMenu;
        private readonly ImageButton _imgBtnCollapse;
        private readonly ImageButton _imgBtnClose;
        private readonly Accordion _accToolbox;

        public DockingContainer()
        {
            _pnlTopMenu = new Panel {ID = "pnlTopMenu"};
            _imgBtnCollapse = new ImageButton();
            _imgBtnClose = new ImageButton { Visible = false };
            _accToolbox = new Accordion();
        }

        protected override void OnInit(EventArgs e)
        {
            Style["height"] = "100%";

            _imgBtnClose.ImageUrl = "~/media/icons/Close_16_16.gif";
            _imgBtnClose.Style["float"] = "right";
            _imgBtnClose.Click += _imgBtnClose_Click;

            _imgBtnCollapse.ImageUrl = "~/media/icons/Collapse_16_16.gif";
            _imgBtnCollapse.Style["float"] = "right";
            _imgBtnCollapse.Click += ImgBtnCollapseClick;

            _pnlTopMenu.Style["background-color"] = "#3B80ED";
            _pnlTopMenu.Style["overflow"] = "auto";

            _accToolbox.CssClass = "gaiax";
            _accToolbox.ScrollBars = ASP.ScrollBars.None;

            base.OnInit(e);
        }

        protected override void CreateChildControls()
        {
            _pnlTopMenu.Controls.Add(_imgBtnCollapse);
            _pnlTopMenu.Controls.Add(_imgBtnClose);
            Controls.Add(_pnlTopMenu);
            Controls.Add(_accToolbox);
            base.CreateChildControls();
        }

        void ImgBtnCollapseClick(object sender, ImageClickEventArgs e)
        {
            _accToolbox.Visible = !_accToolbox.Visible;
        }

        void _imgBtnClose_Click(object sender, ImageClickEventArgs e)
        {
            throw new NotImplementedException();
        }

        public ExtendedPanelCollection DockingItems
        {
            get { return _accToolbox.ExtendedPanels; }
        }
    }
}
